#include "HttpServer.hpp"
#include <memory>

using namespace std;
using namespace Server;

static void Usage(const string &proc)
{
    cout << "\r\n Usage: " << proc << "  local port\r\n"
         << endl;
}

bool CalBack(const HttpRequest &req, HttpResponse &resp)
{
    cout << "---------------------- Http Start----------------------" << endl;
    cout << req.reqBuffer;
    cout << "Method: " << req.moder << endl;
    cout << "HTTP - Version: " << req.version << endl;
    cout << "Url: " << req.url << endl;
    cout << "Path: " << req.path << endl;
    cout << "---------------------- Http   End----------------------" << endl;
    // 没有响应

    string respline = "HTTP/1.1 200 OK\r\n";
    string respblack = "\r\n";
    string respbody = "<html lang=\"en\"><head><meta charset=\"UTF-8\"><title>for test</title><h1>hello world</h1></head><body><p>北京交通广播《一路畅通》“交通大家谈”节目，特邀北京市交通委员会地面公交运营管理处处长赵震、北京市公安局公安交通管理局秩序处副处长 林志勇、北京交通发展研究院交通规划所所长 刘雪杰为您解答公交车专用道6月1日起社会车辆进出公交车道须注意哪些？</p></body></html>";
    resp.respBuffer += respline;
    resp.respBuffer += respblack;
    resp.respBuffer += respbody;

    return true;
}
// ./httpserver 8080
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = atoi(argv[1]);
    unique_ptr<HttpServer> uqrhs(new HttpServer(CalBack, port));
    uqrhs->InitCalServer();
    uqrhs->Start();
    return 0;
}